# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=buttinsky
pkgver=138.1a2a1b2
pkgrel=11
pkgdesc='Provide an open source framework for automated botnet monitoring.'
url='https://github.com/buttinsky/buttinsky'
arch=('any')
groups=('blackarch' 'blackarch-networking')
license=('GPL3')
depends=('python2' 'python2-configobj' 'python2-gevent' 'python2-validictory'
         'python2-pysocks' 'python2-hpfeeds' 'python2-setuptools')
makedepends=('git')
source=("git+https://github.com/buttinsky/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

package() {
  cd $pkgname

  _bins="buttinsky cli netzobparse spawner stack"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/buttinsky"

  install -Dm 644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
  install -Dm 644 COPYING "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm COPYING README.md

  for bin in $_bins; do
    install -m755 "$bin.py" "$pkgdir/usr/share/buttinsky/$bin.py"
  done

  cp -a * "$pkgdir/usr/share/$pkgname/"

  mv "$pkgdir/usr/share/$pkgname/conf/buttinsky.cfg.dist" \
    "$pkgdir/usr/share/$pkgname/conf/buttinsky.cfg"

  chmod u+rwX,g+rwX,o+rX -R \
    "$pkgdir/usr/share/$pkgname/"{behaviors,conf,docs,event_loops,logs,modules,protocols,settings}

  # temporary an exception!
  chmod 777 "$pkgdir/usr/share/$pkgname/logs"
  chmod 777 "$pkgdir/usr/share/$pkgname/logs/buttinsky.log"

  for bin in $_bins; do
    cat > "$pkgdir/usr/bin/$bin" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 $bin.py "\$@"
EOF
    chmod +x "$pkgdir/usr/bin/$bin"
  done
}

